import localforage from 'localforage';

class LocalForageInstance {
  private static instance: LocalForageInstance | null = null;
  private db: LocalForage;

  private constructor() {
    this.db = localforage.createInstance({
      name: 'test',
      storeName: 'test',
      description: 'test'
    });
  }

  public static getInstance(): LocalForageInstance {
    if (!this.instance) {
      this.instance = new LocalForageInstance();
    }
    return this.instance;
  }

  public async setdb(key: string, value: any): Promise<void> {
    await this.db.setItem(key, value);
  }

  public async getdb(key: string): Promise<any> {
    return await this.db.getItem(key);
  }

  public async remove(key: string): Promise<void> {
    await this.db.removeItem(key);
  }

  public async clear(): Promise<void> {
    await this.db.clear();
  }
}

export default LocalForageInstance;
